<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap 实例 - 模态框（Modal）插件</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<h2>加载页面前弹出modals</h2>
<p id='p1'></p>
<!-- 按钮触发模态框 -->

<!-- <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> -->
	<!-- 开始演示模态框 -->
<!-- </button> -->

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					模态框（Modal）标题
				</h4>
			</div>
			<div class="modal-body">
				<input type="text" id="input1"></input>
			</div>
			<div class="modal-footer">
				<!-- <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> -->
				<button type="button" class="btn btn-primary" onclick="goURL()">
					提交更改
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>

<script>
function GetRequest() {
	var url = location.search; //获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i ++) {
			theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}


var gDict={'id':null};
var originalURL='file:///C:/Users/liuyifen/Desktop/some_demos/loadModal/modal.html'

function goURL()
{
    var value=$("#input1").val()
    old_href=location.href
    new_href=old_href+"?id="+value;
    location.href=new_href;
}
$('#myModal').on('hidden.bs.modal',function(event){
    $("#p1").text("你没有选择任何id");
})


$(function(){
    if(!location.search)
    {
        $('#myModal').modal('show');        
        return;
    }
    else
    {
        gDict=GetRequest();
        if(gDict.id!='abc')
        {
            alert('id为空或者不正确。请重新填写！');
            location.href=originalURL;
        } 
        else{
        $("#p1").text("当前id:"+gDict.id);
        }
    }

} );

</script>

</body>
</html>